/**
 * Created by joy on 12/09/2017.
 */
import fs from 'fs'
import EthWalletHelper from '../../common/helpers/chain/EthWalletHelper'
import CommonUtil from '../../common/utils/CommonUtil'
import prompt from 'prompt'

export default async () => {
  const schema = {
    properties: {
      keystoreFile: {
        description: 'Enter keystoreFile',
        type: 'string',
        required: true,
        default: 'keystore'
      },
      password: {
        description: 'Enter password of keystoreFile',
        type: 'string',
        hidden: true,
        replace: '*',
        required: true,
      },
    }
  }

  const args = await CommonUtil.getArgsFromConsole(prompt, schema)
  const { keystoreFile, password } = args
  const ethWalletHelper = new EthWalletHelper()
  const jsonStr = fs.readFileSync(keystoreFile)
  const privateKey = ethWalletHelper.decryptKeystore(jsonStr, password)
  logger.info(privateKey)
}
